/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eproject_sem2;

import java.sql.*;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author ZER0
 */
public class Sever {
    String user = ConnectSQL.user;
    String pass = ConnectSQL.pass;
    String ulr =ConnectSQL.ulr;
    String DriverClass =ConnectSQL.DriverClass;
    Connection con = null;
    public void ShowTable(String t1, String t2, String t3, String t4, String table, JTable sa) {
        try {
            //khai bao model de hien thi bang
            DefaultTableModel listtableModel = new DefaultTableModel();
            Vector tableR1 = new Vector();
            Class.forName(DriverClass);
            con = DriverManager.getConnection(ulr, user, pass);
            String sql = "select * from " + table + "";
            Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            ResultSet rs = st.executeQuery(sql);
            while (rs.next()) {
                Vector r = new Vector();
                r.add(rs.getString(2));
                r.add(rs.getString(3));
                r.add(rs.getString(4));
                r.add(rs.getInt(5));
                tableR1.add(r);
            }
            //goi mo do hien thi thong tin ra bang
            Vector<String> columnNames = new Vector<String>();
            columnNames.addElement("" + t1 + "");
            columnNames.addElement("" + t2 + "");
            columnNames.addElement("" + t3 + "");
            columnNames.addElement("" + t4 + "");
            sa.setModel(listtableModel);
            listtableModel.setDataVector(tableR1, columnNames);
        } catch (SQLException ex) {
            Logger.getLogger(Sever.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Sever.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public void Show(String t1, String t2, String t3, String t4,String t5, String t6, String t7, String t8,String t9, String t10, String t11,String where, JTable sa) {
        try {
            //khai bao model de hien thi bang
            DefaultTableModel listtableModel = new DefaultTableModel();
            Vector tableR1 = new Vector();
            Class.forName(DriverClass);
            con = DriverManager.getConnection(ulr, user, pass);
            String sql = "select * from VotesSent "+where+"";
            Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            ResultSet rs = st.executeQuery(sql);
            while (rs.next()) {
                Vector r = new Vector();
                r.add(rs.getString(t1));
                r.add(rs.getString(t2));
                r.add(rs.getString(t3));
                r.add(rs.getString(t4));
                r.add(rs.getString(t5));
                r.add(rs.getString(t6));
                r.add(rs.getString(t7));
                r.add(rs.getString(t8));
                r.add(rs.getFloat(t9));
                r.add(rs.getFloat(t10));
                r.add(rs.getFloat(t11));
                tableR1.add(r);
            }
            //goi mo do hien thi thong tin ra bang
            Vector<String> columnNames = new Vector<String>();
            columnNames.addElement("" + t1 + "");
            columnNames.addElement("" + t2 + "");
            columnNames.addElement("" + t3 + "");
            columnNames.addElement("" + t4 + "");
            columnNames.addElement("" + t5 + "");
            columnNames.addElement("" + t6 + "");
            columnNames.addElement("" + t7 + "");
            columnNames.addElement("" + t8 + "");
            columnNames.addElement("" + t9 + "");
            columnNames.addElement("" + t10 + "");
            columnNames.addElement("" + t11+ "");
            sa.setModel(listtableModel);
            listtableModel.setDataVector(tableR1, columnNames);
        } catch (SQLException ex) {
            Logger.getLogger(Sever.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Sever.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
